/*
 * JPanelWizardClaseSimpleFinish.java
 *
 * Created on 11-abr-2012, 21:50:37
 */
package com.ufps.cuatro.vistas.asistente.clase.simple;

import com.ufps.cuatro.controlador.render.UtilRender;
import com.ufps.cuatro.modelo.analizador.ObjetoReflexion;
import com.ufps.cuatro.modelo.representacion.ObjetoTipoDatoReflexion;
import com.ufps.cuatro.modelo.representacion.UtilRepresentacion;
import com.ufps.cuatro.util.Representacion;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.event.ListDataListener;
import org.jdesktop.application.Action;

/**
 *
 * @author Catc
 */
public class JPanelWizardClaseSimpleFinish extends javax.swing.JPanel {
    private static final long serialVersionUID = -4825775907629206487L;
    
    private ObjetoTipoDatoReflexion objTipoDato;
    private final ArrayList<ObjetoReflexion> objMetodos;
    private ArrayList<ObjetoReflexion> objMetodosDisponibles;
    private ArrayList<ObjetoReflexion> objMetodosAgregados;
    private final ArrayList<ObjetoReflexion> objMetodosSinRepresentacion;

    /** Creates new form JPanelWizardClaseSimpleFinish */
    public JPanelWizardClaseSimpleFinish(ObjetoTipoDatoReflexion objTipoDato) {
        initComponents();
        this.objTipoDato = objTipoDato;        
        this.jLabelClase.setText(objTipoDato.getStrClassPath());
        String strToolTips = jLabelInfoMethod.getText() + 
                Representacion.objPropiedadesRepresentacion.getProperty("Utileria.swing.representaciones.alias.metodo.getter") + ", " +
                Representacion.objPropiedadesRepresentacion.getProperty("Utileria.swing.representaciones.alias.metodo.is") + "</p></html>";
        jLabelInfoMethod.setText(strToolTips);
        objMetodos = UtilRepresentacion.devolverPropiedadesClase(objTipoDato.getObjClass(), UtilRepresentacion.PROPIEDADES_METODOS_SALIDA, false);
        objMetodosSinRepresentacion = UtilRepresentacion.devolverPropiedadesClase(objTipoDato.getObjClass(), UtilRepresentacion.PROPIEDADES_METODOS_SALIDA, true);
        
        objMetodosDisponibles = new ArrayList<ObjetoReflexion>();
        objMetodosAgregados = new ArrayList<ObjetoReflexion>();
        
        objMetodosDisponibles.addAll(objMetodos);
        
        UtilRender.helperRenderJList(jListDisponibles, objMetodosDisponibles, 0, javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabelClase = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jCheckBoxConfirmar = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        jButtonAdd = new javax.swing.JButton();
        jButtonAddAll = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButtonDel = new javax.swing.JButton();
        jButtonDelAll = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jButton5 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListDisponibles = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        jListAgregadas = new javax.swing.JList();
        jLabelInfoMethod = new javax.swing.JLabel();
        jLabelToolTips = new javax.swing.JLabel();

        jLabel2.setText("Clase:");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabelClase.setBackground(new java.awt.Color(255, 255, 255));
        jLabelClase.setText("Información de la Clase");
        jLabelClase.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jLabelClase.setName("jLabelClase"); // NOI18N
        jLabelClase.setOpaque(true);

        jLabel1.setText("Cree el Campo Computado con las Propiedades que desea visualizar en la Vista Simplificada.");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel4.setBackground(new java.awt.Color(255, 255, 255));
        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ufps/cuatro/resources/icono app x 48.png"))); // NOI18N
        jLabel4.setText("<html><b>Bienvenido al Asistente de Representación de Clases.</b><br> <p> Este asistente le permitirá generar Vistas Simplificadas de Clases por medio de Campos Comptados que asociaran las Propiedades Seleccionadas.</p></html>");
        jLabel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jLabel4.setName("jLabel4"); // NOI18N
        jLabel4.setOpaque(true);

        jCheckBoxConfirmar.setFont(new java.awt.Font("Tahoma", 1, 11));
        jCheckBoxConfirmar.setText("<html>Confirma la Configuración Actual para Generar una Nueva Vista Simplificada.</html>");
        jCheckBoxConfirmar.setName("jCheckBoxConfirmar"); // NOI18N

        jLabel5.setText("Propiedades Seleccionadas.");
        jLabel5.setName("jLabel5"); // NOI18N

        jToolBar1.setFloatable(false);
        jToolBar1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jToolBar1.setName("jToolBar1"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(JPanelWizardClaseSimpleFinish.class, this);
        jButtonAdd.setAction(actionMap.get("add")); // NOI18N
        jButtonAdd.setFocusable(false);
        jButtonAdd.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonAdd.setName("jButtonAdd"); // NOI18N
        jButtonAdd.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButtonAdd);

        jButtonAddAll.setAction(actionMap.get("addAll")); // NOI18N
        jButtonAddAll.setFocusable(false);
        jButtonAddAll.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonAddAll.setName("jButtonAddAll"); // NOI18N
        jButtonAddAll.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButtonAddAll);

        jSeparator1.setName("jSeparator1"); // NOI18N
        jToolBar1.add(jSeparator1);

        jButtonDel.setAction(actionMap.get("del")); // NOI18N
        jButtonDel.setFocusable(false);
        jButtonDel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonDel.setName("jButtonDel"); // NOI18N
        jButtonDel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButtonDel);

        jButtonDelAll.setAction(actionMap.get("delAll")); // NOI18N
        jButtonDelAll.setFocusable(false);
        jButtonDelAll.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonDelAll.setName("jButtonDelAll"); // NOI18N
        jButtonDelAll.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButtonDelAll);

        jSeparator2.setName("jSeparator2"); // NOI18N
        jToolBar1.add(jSeparator2);

        jButton5.setAction(actionMap.get("help")); // NOI18N
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setName("jButton5"); // NOI18N
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton5);

        jLabel6.setText("Propiedad Disponibles.");
        jLabel6.setName("jLabel6"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jListDisponibles.setName("jListDisponibles"); // NOI18N
        jListDisponibles.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListDisponiblesValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jListDisponibles);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jListAgregadas.setName("jListAgregadas"); // NOI18N
        jListAgregadas.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListAgregadasValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(jListAgregadas);

        jLabelInfoMethod.setText("<html><p>Seleccione un Método para Visualizar su Definición.</html>");
        jLabelInfoMethod.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jLabelInfoMethod.setName("jLabelInfoMethod"); // NOI18N

        jLabelToolTips.setText("<html><p>Las Propiedades de Salida son Identificadas como aquellos métodos que devuelve un Valor y que estan identificados por nombres que empiezan por :");
        jLabelToolTips.setName("jLabelToolTips"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, 0, 0, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelClase, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE))
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
                    .addComponent(jCheckBoxConfirmar, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)))
                    .addComponent(jLabelInfoMethod, 0, 0, Short.MAX_VALUE)
                    .addComponent(jLabelToolTips, 0, 0, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabelClase))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBoxConfirmar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelInfoMethod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelToolTips, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jListDisponiblesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListDisponiblesValueChanged
        if(jListDisponibles.getSelectedIndex() == -1){            
            return;
        }
        ObjetoReflexion objMetodo = (ObjetoReflexion) jListDisponibles.getModel().getElementAt(jListDisponibles.getSelectedIndex());
        UtilRender.helperIconLabelObjetoReflexiontoString(jLabelInfoMethod, objMetodo);        
    }//GEN-LAST:event_jListDisponiblesValueChanged

    private void jListAgregadasValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListAgregadasValueChanged
        if(jListAgregadas.getSelectedIndex() == -1){            
            return;
        }
        ObjetoReflexion objMetodo = (ObjetoReflexion) jListAgregadas.getModel().getElementAt(jListAgregadas.getSelectedIndex());
        UtilRender.helperIconLabelObjetoReflexiontoString(jLabelInfoMethod, objMetodo);        
    }//GEN-LAST:event_jListAgregadasValueChanged

    @Action
    public void add() {
        if(jListDisponibles.isSelectionEmpty() && jListDisponibles.getSelectedIndex() == -1){
            UtilRender.msgInformacion("Debe Seleccionar un Método.", this);
            return;
        }
        List objSeleccionados = jListDisponibles.getSelectedValuesList();
        objMetodosDisponibles.removeAll(objSeleccionados);
        objMetodosAgregados.addAll(objSeleccionados);
        UtilRender.helperRenderJList(jListAgregadas, objMetodosAgregados, 0, javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        UtilRender.helperRenderJList(jListDisponibles, objMetodosDisponibles, 0, javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    }

    @Action
    public void addAll() {
        if(objMetodosDisponibles.isEmpty()){
            UtilRender.msgInformacion("No existen Métodos Disponibles.", this);
            return;
        }
        if(!UtilRender.msgConfirmar("¿Desea Agregar Todos los Métodos Disponibles?", this)){
            return;
        }                
        objMetodosAgregados.addAll(objMetodosDisponibles);
        objMetodosDisponibles.clear();
        UtilRender.helperRenderJList(jListAgregadas, objMetodosAgregados, 0, javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        UtilRender.helperRenderJList(jListDisponibles, objMetodosDisponibles, 0, javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    }

    @Action
    public void del() {
        if(jListAgregadas.isSelectionEmpty() && jListAgregadas.getSelectedIndex() == -1){
            UtilRender.msgInformacion("Debe Seleccionar un Método.", this);
            return;
        }
        List objSeleccionados = jListAgregadas.getSelectedValuesList();
        objMetodosAgregados.removeAll(objSeleccionados);
        objMetodosDisponibles.addAll(objSeleccionados);
        UtilRender.helperRenderJList(jListAgregadas, objMetodosAgregados, 0, javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        UtilRender.helperRenderJList(jListDisponibles, objMetodosDisponibles, 0, javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    }

    @Action
    public void delAll() {
        if(objMetodosAgregados.isEmpty()){
            UtilRender.msgInformacion("No existen Métodos Agregados.", this);
            return;
        }
        if(!UtilRender.msgConfirmar("¿Desea Quitar Todos los Métodos Agregados?", this)){
            return;
        }                
        objMetodosDisponibles.addAll(objMetodosAgregados);
        objMetodosAgregados.clear();
        UtilRender.helperRenderJList(jListAgregadas, objMetodosAgregados, 0, javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        UtilRender.helperRenderJList(jListDisponibles, objMetodosDisponibles, 0, javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    }

    @Action
    public void help() {
         UtilRender.openDialogHelp(JPanelWizardClaseSimpleFinish.class, "JPanelWizardClaseSimpleFinish");
    }
    
    public ArrayList<ObjetoReflexion> getObjMetodosAgregados() {
        return objMetodosAgregados;
    }

    public ObjetoTipoDatoReflexion getObjTipoDato() {
        return objTipoDato;
    }
    
    public void addCheckBoxActionListener(ActionListener l) {
        jCheckBoxConfirmar.addActionListener(l);
    }
    
    public boolean isCheckBoxSelected() {
        return jCheckBoxConfirmar.isSelected();
    }  
    
    public boolean isListEmpty(){
        return this.objMetodosAgregados.isEmpty();
    }
    
    public void addListDataListener(ListDataListener i){
        this.jListAgregadas.getModel().addListDataListener(i);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButtonAdd;
    private javax.swing.JButton jButtonAddAll;
    private javax.swing.JButton jButtonDel;
    private javax.swing.JButton jButtonDelAll;
    private javax.swing.JCheckBox jCheckBoxConfirmar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabelClase;
    private javax.swing.JLabel jLabelInfoMethod;
    private javax.swing.JLabel jLabelToolTips;
    private javax.swing.JList jListAgregadas;
    private javax.swing.JList jListDisponibles;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables
}
